package Sutdentdao;

import pojo.sutdent;
import test1.test1;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

public class Studentdao {//对数据表进行增删改查
    public ArrayList<sutdent> getsutdents(){
        ArrayList<sutdent> list =new ArrayList<sutdent>();
        //1.连接数据库
        Connection conn = test1.getConn();
        //2. 编写SQL语句
        String sql ="select * from sutdent";
        try {
            PreparedStatement pst =conn.prepareStatement(sql);
            ResultSet rs = pst.executeQuery();//ResultSet是一个集合
            while (rs.next()){
                sutdent student = new sutdent(rs.getInt("id"),rs.getString(2),rs.getString(3));
                list.add(student);
            }
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
        return list;

    }
}
